let http=require('http');//导入http模块
let fs=require('fs');//导入fs模块
let path=require("path")
const PORT='80';//设置端口
console.log(__dirname)
http.createServer((req,res)=>{
    res.setHeader("Access-Control-Allow-Origin","*")
    console.log(req.url)
    if(req.url.endsWith("/")){
        res.setHeader( 'Content-Type','text/html');
        fs.readFile("."+req.url+"index.html",function(err,data){
            res.end(data);
        });
    }else{
        fs.readFile("."+req.url,function (err,data) {
            res.end(data);
        })
    }
}).listen(PORT,err=>{
    if(err){
        console.log('发生错误：',err);
    }
});

console.log(`服务器正在运行，端口为：${PORT}.....`);
